/**
TODO: SessionID or RoomID
Pass the session id to server..
**/

define([
	"../menu/menu-sticky-text",
	"../menu/nicEdit"
	], 
function (
	menu,
	nicEdit
	) {

    return {
    	menu : menu,
		textBefore : null,
		colorBefore : null,
    	
        init: function () {
			console.log('Init Kinetic..');
			App.stickyText.menu.init();
		},
		
		createObject : function(point){
			console.log("create text");
			App.stickyText.menu.createObject(point);
		},
		
		enterEditMode : function(id){
			if(!App.stickyText.menu.isShow){
				$("#"+id).css( 'background-color',$("#"+id).css("background-color") );
				$("#"+id).css( 'border','5px solid red' );
				$("#"+id).css( 'overflow',"hidden" );
				$("#"+id).draggable( 'disable' );
				$("#"+id).resizable( 'disable' );
				$("#"+id).addClass("active-sticky");
				App.stickyText.menu.isEditMode = true;
				App.stickyText.menu.id = id;
				App.stickyText.menu.show();
				App.stickyText.lastTop=$("#"+id).css( 'top');
				$("#"+id).css( 'top','0px' );
				
				$("#"+id+"-c").hide(); 
				$("#"+id).find(".ui-resizable-handle").hide();
				App.stickyText.textBefore = $("#text_content_"+id).html();
				App.stickyText.colorBefore = $("#"+id).css( 'background-color');
				var bgColorInHex = App.Util.colorToHex(App.stickyText.colorBefore);
				for(var i=0;i<$.jPicker.List.length;i++)
				{
					if($.jPicker.List[i].id == "stickyJPicker")
					{
						$.jPicker.List[i].color.active.val('hex', bgColorInHex, this);
						break;
					}
				}
			
				App.stickyText.menu.panel.addInstance(id);
				var menuTop =  $("#"+id).offset().top + $("#"+id).height()+30;
				var wWidth = $(window).width(); 
				var wHeight = $(window).height(); 
				if(menuTop +$("#nic-sticky-edit-panel-container" ).height()>wHeight)
				{
					menuTop =  $("#"+id).offset().top - $("#"+id).height()-90;
				}
				var menuLeft =  $("#"+id).offset().left;
				$("#nic-sticky-edit-panel-container" ).offset({ top:menuTop, left: menuLeft});
			}
		}
	}
});